// pages/record/record.js
let util = require("../../utils/util.js");
Page({
    //分享
    onShareAppMessage: function () { },
    /**
     * 页面的初始数据
     */
    data: {
        detail: [],
        timeArr:[]
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var userInfo = wx.getStorageSync("userInfo");
        if(!!userInfo && userInfo != ""){
            this.setData({
                userInfo: JSON.parse(userInfo)
            });
        }
        this.getdetail();
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    //获取页面信息
    getdetail: function () {
        var userinfo = JSON.parse(wx.getStorageSync("userInfo")).smAdmin.id;
        let that = this;
        var timeArr = this.data.timeArr;
        util.wxAjax("glHabit/myHabit", "post", {
            adminid: userinfo,
            pageNum: 1
        }, function (res) {
            var data = res.data;
            if(data.result == 200 || data.result == "200"){
                var jsonData = data.data;
                var temp = {};
                var time = "";
                for(var i=0;i<jsonData.length;i++){
                    time = jsonData[i].createDate.split(" ")[0];
                    if(!temp[time]){
                        temp[time] = {list:[],time:""};
                        temp[time].list = [];
                        temp[time].time = time.split("-");
                        timeArr.push({time:time,month:time.split("-")[1],day:time.split("-")[2]});
                    }
                    temp[time].list.push(jsonData[i]);
                }
                that.setData({
                    detail: temp,
                    timeArr: timeArr
                })
            }else{
                wx.showToast({
                    title: data.msg,
                    icon:"none"
                })
            }
        })
    },
    //图片预览
    prevPicture: function (options) {
        var images = options.currentTarget.dataset.image;
        console.log(images);
        wx.previewImage({
            urls: [images],
            success: function (res) {}
        });
    },
})